<?php


namespace app\admin\controller\goods;

use app\common\controller\Backend;
use think\Db;
class Integer extends Backend
{

    /**
     * Goods模型对象
     * @var \app\admin\model\goods\Integer
     */
    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\admin\model\goods\Integer;

    }


    /**
     * 查看
     */
    public function index()
    {
        //当前是否为关联查询
        $this->relationSearch = false;
        //设置过滤方法
        $this->request->filter(['strip_tags', 'trim']);
        if ($this->request->isAjax()) {
            //如果发送的来源是Selectpage，则转发到Selectpage
            if ($this->request->request('keyField')) {
                return $this->selectpage();
            }
            list($where, $sort, $order, $offset, $limit) = $this->buildparams();

            $list = $this->model
                ->where(['status'=>1,'type'=>1])
                ->where($where)
                ->order($sort, $order)
                ->paginate($limit)->each(function($item,$key){
                    $cate_title    = Db::name('cate_goods')->where('id',$item['cate_id'])->field('pid,title')->find();
                    $cate_name     = Db::name('cate_goods')->where('id',$cate_title['pid'])->value('title');
                    $item['title'] = $cate_name . ' L__ ' . $cate_title['title'];
                    switch($item['status'])
                    {
                        case 1;
                            $item['status'] = '是';
                            break;
                        case 2;
                            $item['status'] = '否';
                            break;
                    }
                    return $item;
                });

            foreach ($list as $row) {
                $row->visible(['id','name','cate_id','image','num','money','status','title','create_time']);

            }

            $result = array("total" => $list->total(), "rows" => $list->items());

            return json($result);
        }
        return $this->view->fetch();
    }

}